package com.yanqu.road.server.gameplayer.module.activity.horserun.event;

import com.yanqu.road.entity.activity.horserun.HorseRunUserGamingData;
import com.yanqu.road.entity.activity.horserun.config.HorseRunEventConfig;
import com.yanqu.road.logic.activity.horserun.HorseRunConfig;
import com.yanqu.road.logic.helper.WeightHelper;
import com.yanqu.road.pb.activity.HorseRunProto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  lottery("墨璃事件",9),
 */
public class HorseRunLotteryDrawEvent extends HorseRunBaseEvent{

    @Override
    public HorseRunProto.EventResult.Builder meet(HorseRunUserGamingData userGamingData, HorseRunConfig config, HorseRunEventConfig eventConfigById) {
        HorseRunProto.EventResult.Builder builder = HorseRunProto.EventResult.newBuilder();
        int eventId = eventConfigById.getId();

        builder.setError(0);
        //加到日志里面
        addUserLog(userGamingData,config,1,eventId,new ArrayList<>(),builder);
        //进行中
        eventGoing(userGamingData);
        return builder;
    }

    @Override
    public HorseRunProto.EventResult.Builder deal(HorseRunUserGamingData userGamingData, HorseRunDealEventArg arg, HorseRunConfig config, HorseRunEventConfig eventConfigById) {
        HorseRunProto.EventResult.Builder builder = HorseRunProto.EventResult.newBuilder();
        int eventId = eventConfigById.getId();

        builder.setError(0);
        List<Integer> paramList = eventConfigById.getParamList();

        Map<Integer,Integer> weightMap = new HashMap<Integer,Integer>();
        for (int i = 0; i < 4; i++) {
            weightMap.put(paramList.get(i), paramList.get(i+4));
        }
        int randomValue = WeightHelper.getRandomValue(weightMap);
        int nanGuaNum = 3 - paramList.indexOf(randomValue);
        int realExpAdd = randomValue * userGamingData.getOpenGameMultiple();


        builder.setNanguaNum(nanGuaNum);

        List<Integer> logParam = new ArrayList<>();
        logParam.add(nanGuaNum);
        logParam.add(realExpAdd);

        userGamingData.addExpSum(realExpAdd);
        addUserLog(userGamingData,config,2,eventId,logParam,builder);
        eventDone(userGamingData);
        return builder;
    }
}
